
package com.founder.bdyx.modules.sys.service.impl;

import com.founder.bdyx.core.entity.ProcessResult;
import com.founder.bdyx.core.util.MD5Utils;
import com.founder.bdyx.core.util.RandomUtil;
import com.founder.bdyx.modules.sys.mapper.ApplyInfoMapper;
import com.founder.bdyx.modules.sys.mapper.SysRoleMapper;
import com.founder.bdyx.modules.sys.mapper.SysUserMapper;
import com.founder.bdyx.modules.sys.mapper.SysUserRoleMapper;
import com.founder.bdyx.modules.sys.model.*;
import com.founder.bdyx.modules.sys.service.ApplyInfoService;
import com.founder.bdyx.modules.sys.service.MenuService;
import com.founder.bdyx.modules.sys.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

//import com.founder.bdyx.modules.sys.service.MailService;

/**
 * @author yang.xuefeng
 */
@Service("applyInfoService")
@Transactional
public class ApplyInfoServiceImpl implements ApplyInfoService {

    @Autowired
    private ApplyInfoMapper applyInfoMapper;

//    @Autowired
//    private MailService mailService;

    @Override
    public List<ApplyInfo> getAll(ApplyInfo applyInfo, String keyword, String paystatus) {
        PageHelper.startPage(applyInfo.getPage(),applyInfo.getRows());
        /*Example example=new Example(ApplyInfo.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtils.isNotBlank(keyword)){
            keyword="%"+keyword+"%";
            criteria.andLike("patientName",keyword);
            criteria.orLike("inPatientNo",keyword);
        }
        return applyInfoMapper.selectByExample(example);*/
        return applyInfoMapper.getAllInfo(keyword,paystatus);
    }

    @Override
    public List<ApplyInfo> getPickUpAll(String keyword, String paystatus) {
        return applyInfoMapper.getPickUpAll(keyword,paystatus);
    }

    @Override
    public List<ApplyInfo> getSendAll(String keyword, String paystatus, String isPrint) {
        return applyInfoMapper.getSendAll(keyword,paystatus,isPrint);
    }

    @Override
    public Page<ApplyInfo> getClosedAll(String keyword, String paystatus) {
        return applyInfoMapper.getClosedAll(keyword,paystatus);
    }

    @Override
    public List<ApplyInfo> getAllForFinish(ApplyInfo applyInfo, String keyword, String transType) {
        //PageHelper.startPage(applyInfo.getPage(),applyInfo.getRows());
        return applyInfoMapper.getAllForFinish(keyword,transType);
    }

    @Override
    public ApplyInfo getById(Integer id) {
        return applyInfoMapper.getById(id);
    }

    @Override
    public ApplyInfo getByAppId(String appid) {
        return applyInfoMapper.getByAppId(appid);
    }

    @Override
    public int updatePickUpNoticeById(Integer id) {
        String randomCode = RandomUtil.randomCode();
        return applyInfoMapper.updateNoticeById(id,randomCode);
    }

    @Override
    public void batchPickUpNotice(Integer[] list) {
        for (Integer id:list){
            String randomCode = RandomUtil.randomCode();
            applyInfoMapper.updateNoticeById(id,randomCode);
        }
    }

    @Override
    public int updateLogisticsNo(String logisticsNo, Integer id) {
        return applyInfoMapper.updateLogisticsNoById(logisticsNo,id);
    }

    @Override
    public int updatePickUpNo(String logisticsNo, Integer id) {
        return applyInfoMapper.updatePickUpNoById(logisticsNo,id);
    }

    @Override
    public int updateApplyInfo(ApplyInfo applyInfo) {
        return applyInfoMapper.updateApplyInfo(applyInfo);
    }

    @Override
    public int updatePrepayId(ApplyInfo applyInfo) {
        return applyInfoMapper.updatePrepayId(applyInfo);
    }
}
